local lume = require('lib.lume')
local Tile = require('src.gen.tile')
local BaseState = require("states.gen.base_state")

return Class{
   __includes = BaseState,
   init = function (self)
      BaseState.init(self)
   end,
   
   load = function (self)
      --Add some enemies
   end,

   update = function (self, dt)
      Game.upool:update(dt)
   end,
   
   draw = function (self)
      Game.current_screen:draw({Game.current_map})
      Game.current_screen:draw({Game.upool})
      Game.current_screen:draw({Game.cursor.grid, Game.cursor})
      self.gui:draw()
   end,

   select = function (self)
      if Game.cursor.is_hovering then return end
      local x, y = Game.cursor:get_position ()
      local _u = Game.upool:unit_at(x, y)
      if _u then
	 self.selection = _u
	 _u:select()
      end
   end,

   menu_toggle = function (self)
      if self.ul or self.ulc then
	 lume.remove(self.gui.elements, self.ul)
	 self.ul = nil
	 return
      end
      self.ul = self.gui:ul(300, 200, 400, 33, "Menu")
      self.ul.onclick = function (i, b)
	 Game:switch_state("mainmenu")
	 lume.remove(self.gui.elements, self.ul)
	 self.ul = nil
      end
   end,
   
}
